<%@ page language="java" contentType="text/html; charset=UTF-8"%>

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>MobileWorld - 登录</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f3f4f6;
            display: flex;
            justify-content: center;
            align-items: flex-start;
            min-height: 100vh;
            padding-top: 50px;
        }
        .container {
            width: 100%;
            max-width: 400px;
            padding: 2rem;
            background: #ffffff;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            text-align: center;
            animation: fadeInDown 0.8s ease-out;
        }
        h1 {
            color: #0078D7;
            margin-bottom: 1rem;
            font-size: 1.8rem;
        }
        form {
            display: flex;
            flex-direction: column;
            gap: 1rem;
        }
        label {
            font-weight: bold;
            text-align: left;
        }
        input[type="text"], input[type="password"] {
            padding: 0.8rem;
            font-size: 1rem;
            border: 1px solid #ddd;
            border-radius: 5px;
            outline: none;
            transition: border-color 0.3s ease, box-shadow 0.3s ease;
        }
        input[type="text"]:focus, input[type="password"]:focus {
            border-color: #0078D7;
            box-shadow: 0 0 8px rgba(0, 120, 215, 0.2);
        }
        button {
            background-color: #0078D7;
            color: white;
            cursor: pointer;
            border: none;
            border-radius: 5px;
            padding: 0.8rem;
            font-size: 1rem;
            transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
        }
        button:hover {
            background-color: #005bb5;
            transform: scale(1.05);
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .message {
            margin-bottom: 1rem;
            padding: 0.8rem;
            font-size: 0.9rem;
            border-radius: 5px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .message.success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        .message.error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        .footer {
            margin-top: 1rem;
            font-size: 0.9rem;
            color: #555;
        }
        .footer a {
            color: #0078D7;
            text-decoration: none;
            font-weight: bold;
            transition: color 0.3s ease;
        }
        .footer a:hover {
            color: #005bb5;
        }
        /* 动画效果 */
        @keyframes fadeInDown {
            from {
                opacity: 0;
                transform: translateY(-20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        /* Toast 动态效果 */
        .toast {
            position: fixed;
            top: -100px;
            left: 50%;
            transform: translateX(-50%);
            background-color: #28a745;
            color: white;
            padding: 1rem 2rem;
            border-radius: 5px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            font-size: 0.9rem;
            opacity: 0;
            transition: all 0.5s ease;
            z-index: 1000;
        }
        .toast.error {
            background-color: #ff4d4f;
        }
        .toast.show {
            top: 20px;
            opacity: 1;
        }
    </style>
</head>
<body>
<%-- Toast 提示消息 --%>
<% String message = request.getParameter("message"); %>
<% if (message != null) { %>
<div class="toast" id="toast"><%= message %></div>
<% } %>

<%-- 错误信息显示 --%>
<% if (request.getAttribute("error") != null) { %>
<div class="toast error" id="toast"><%= request.getAttribute("error") %></div>
<% } %>

<div class="container">
    <h1>欢迎登录 MobileWorld</h1>
    <form action="login" method="post">
        <label for="username">用户名：</label>
        <input type="text" id="username" name="username" placeholder="请输入用户名" required>

        <label for="password">密码：</label>
        <input type="password" id="password" name="password" placeholder="请输入密码" required>

        <button type="submit">登录</button>
    </form>
    <div class="footer">
        没有账号？ <a href="register.jsp">立即注册</a>
    </div>
</div>

<script>
    // Toast 显示与隐藏逻辑
    window.onload = function() {
        const toast = document.getElementById('toast');
        if (toast) {
            toast.classList.add('show');
            // 3秒后隐藏
            setTimeout(() => {
                toast.classList.remove('show');
            }, 3000);
        }
    };
</script>
</body>
</html>
